package club.pchome.controller;

import club.pchome.dto.Result;
import club.pchome.service.CUserService;
import club.pchome.service.TOrderService;
import club.pchome.service.TWantBuyService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 后台首页数据显示
 * @date 2019/6/27 0027
 */
@RestController
public class IndexController {


    @Autowired
    private CUserService cUserService;
    @Autowired
    private TWantBuyService tWantBuyService;
    @Autowired
    private TOrderService tOrderService;
    /**
     * 获取后台首页数据
     * @return
     */
    @PostMapping("/mainDataView")
    public Result<String> mainDataView(){
        Map<String, Object> map = new HashMap<String, Object>();
        //用户总数
        map.put("userCount" , cUserService.userCount());
        //当日注册
        map.put("todayRegCount" , cUserService.todayRegCount());
        //当前求购
        map.put("getWantOrderCount" , tWantBuyService.getWantOrderCount(null));
        //当日成交
        map.put("todaySuccessOrder" , tOrderService.todaySuccessOrder());
        map.put("data", "");

        String jsonStr = JSONObject.toJSONString(map);
        return Result.initSuccessResult(jsonStr);
    }


}